package com.xmx.ndmallwxapi.controller;


import com.xmx.common.utils.R;
import com.xmx.ndmallwxapi.feign.ProductFeignClient;
import com.xmx.ndmallwxapi.service.GoodService;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/wx/goods")
public class GoodsController {

    @Resource
    ProductFeignClient productFeignClient;

    @Resource
    GoodService goodService;

    @GetMapping("/count")
    public R genum(){
        return productFeignClient.count();
    }

    @GetMapping("/detail")
    public R detail(@RequestParam("id") Integer id){
        Map detaile = goodService.detaile(id);
//        httpRequest.getHeaders().add("X-Litemall-Token","aaa");
        return R.ok().put("data",detaile);
    }

    @GetMapping("/info")
    public R info(@RequestParam("id") Integer id){
        Map detaile = goodService.detaile(id);
        return R.ok().put("data",detaile);
    }

    @GetMapping("/related")
    public R related(@RequestParam("id") Integer id){
        Map related = goodService.related(id);
        return R.ok().put("data",related);
    }

    @GetMapping("/list")
    public R list(@RequestParam("brandId")Integer brandId,Integer page,Integer limit){
        R brandList = productFeignClient.getBrandList(brandId, page, limit);
        return brandList;
    }
}
